package com.example.zzl.viewmodel.HomeFragment;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import com.example.zzl.R;
import com.example.zzl.adapter.HomeFragment.HomeFragmentAdapter;
import com.example.zzl.databinding.FragmentHomeBinding;
import com.example.zzl.view.fragment.HomeFragment.NewsFragment;
import com.example.zzl.view.fragment.HomeFragment.RecommendFragment;
import com.example.zzl.view.fragment.HomeFragment.SessionFragment;
import com.example.zzl.viewmodel.BaseCallback;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by ligg on 2017/2/8.
 */

public class HomeFragmentPresenter  {

    private Context context;
    private Callback callback;
    private FragmentHomeBinding db;
    private String[] titles;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };
    private List<Fragment> fragments;
    private HomeFragmentAdapter adapter;


    public void init() {
        fragments = new ArrayList<Fragment>();
        RecommendFragment recommendFragment = RecommendFragment.newInstance(null);
        NewsFragment newsFragment = NewsFragment.newInstance(null);
        SessionFragment sessionFragment = SessionFragment.newInstance(null);
        Collections.addAll(fragments, recommendFragment, newsFragment, sessionFragment);


        titles = context.getResources().getStringArray(R.array.home_title);
        adapter = new HomeFragmentAdapter(callback.getManager(), fragments, titles);
    }

    public void initView() {
        db.toolbar.setTitle("");
        callback.setToolbar();
        db.vp.setAdapter(adapter);
        db.tl.setupWithViewPager(db.vp);
        /*db.swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_dark, android.R.color.holo_orange_dark,
                android.R.color.holo_blue_dark, android.R.color.holo_green_dark);
        db.swipeRefreshLayout.setOnRefreshListener(this);*/
    }



    public interface Callback extends BaseCallback{
        FragmentManager getManager();
        void setToolbar();
    }

    public HomeFragmentPresenter(Context context, Callback callback) {
        this.context = context;
        this.callback = callback;
    }

    public FragmentHomeBinding getDb() {
        return db;
    }

    public void setDb(FragmentHomeBinding db) {
        this.db = db;
    }
}
